﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class BuscaDAO extends CI_Model{
	

	public function __construct()
    {
        parent::__construct();
		$this->load->database();
		$this->load->library('Dominio');
    }
	
	function countBuscaCliente()
	{
		$match = $this->input->post('busca');
		$this->db->order_by('nome_cliente', 'asc');
		$this->db->like('nome_cliente',$match);
		$query = $this->db->count_all_results('clientes');
		return $query;
	}
	
	function getBuscaCliente($num, $offset)
	{
		$match = $this->input->post('busca');
		$this->db->order_by('nome_cliente', 'asc');
		$this->db->like('nome_cliente',$match);
		$query = $this->db->get('clientes', $num, $offset);
		if($query->num_rows() > 0) {
			foreach ($query->result() as $r){
				$cols[] = new Cliente(
								$r->nome_cliente,
								$r->sexo,
								$r->data_nascimento,
								$r->endereco,
								$r->telefone,
								$r->email,
								$r->outros_contatos,
								$r->parentes,
								$r->historico_familiar,
								$r->etnia,
								$r->altura,
								$r->peso,
								$r->glicemia,
								$r->pressao_arterial,
								$r->contra_indicacao,
								$r->historico_doencas,
								$r->plano_saude,
								$r->medicos_preferidos,
								$r->onde_costuma_comprar,
								$r->id_cliente
							);
			}
			return $cols;
		}
		return FALSE;
	}
}

/* End of file clientedao.php */
/* Location: ./application/models/clientedao.php */